package main

import (
	"fmt"
	"strconv"
	"time"
)

func main() {
	in := make(chan int, 3)
	out := make(chan int, 3)
	defer close(in)
	defer close(out)
	go chIn(in)
	go chOut(in, out)
	time.Sleep(10 * time.Second)
	fmt.Println("over")
}

func chIn(in chan<- int) {
	index := 0
	for {
		index++
		in <- index
		fmt.Println("进入in：" + strconv.Itoa(index))
		time.Sleep(time.Second)
		fmt.Println("in的长度是：" + strconv.Itoa(len(in)))
	}
}

func chOut(in <-chan int, out chan<- int) {
	for {
		outNum := <-in
		fmt.Println("退出in：" + strconv.Itoa(outNum))
		fmt.Println("in的长度是：" + strconv.Itoa(len(in)))
		out <- outNum
		fmt.Println("进入out：" + strconv.Itoa(outNum))
		fmt.Println()
		time.Sleep(time.Second)
	}
}
